/*
 * Copyright 2014 Graham Smith
 */
package uk.co.wobblycogs.vegas.riff;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;

/**
 *
 * @author Graham Smith
 */
public class RIFFHeader extends RIFFChunk {

	private String vfFile;
	private String defaultProjectFolder;
	private String appDataFolder;

	public RIFFHeader() {
	}

	@Override
	public void load(ByteBuffer byteBuffer) {
		super.load(byteBuffer);

		//Extract various bits of known data from the binary blob.
		ByteBuffer bb = ByteBuffer.wrap(getData());
		bb = bb.order(ByteOrder.LITTLE_ENDIAN);

		//Skip the first 24 bytes as they are the type and length information.
		bb.position(24);
		bb.mark();

		//The first few bytes (it seems to always be 136) appear to describe the
		//rest of the chunk.
		int indexLength = bb.getInt();

		//There's a bunch of bytes that are unknown.
		RIFFUtilities.move(bb, 52);

		//The next four four byte blocks describe the number of and length of
		//file paths. There seems to always be three paths.
		int pathCount = bb.getInt();
		int vfPathLength = bb.getInt();
		int defaultProjectPathLength = bb.getInt();
		int appDataPathLength = bb.getInt();

		//Move back to the marked position and then forward to the start of the
		//the paths.
		bb.reset();
		RIFFUtilities.move(bb, indexLength);

		//Extract the paths.
		vfFile = RIFFUtilities.getString(bb, vfPathLength);
		defaultProjectFolder = RIFFUtilities.getString(bb, defaultProjectPathLength);
		appDataFolder = RIFFUtilities.getString(bb, appDataPathLength);
	}

	public String getVfFile() {
		return vfFile;
	}

	public String getDefaultProjectFolder() {
		return defaultProjectFolder;
	}

	public String getAppDataFolder() {
		return appDataFolder;
	}
}
